<?php $this->pageHeader('Rediger vakt'); ?>

<p id="top_right_links">
    <a href="<?php echo $this->url(array('module' => 'core', 'controller' => 'shift', 'action' => 'view', 'id' => $this->shift['id'])); ?>" class="button"><img src="<?php echo $this->imageLink('images/icons/arrow_right.png'); ?>" />Vis vakt</a>
    <a href="<?php echo $this->url(array('module' => 'core', 'controller' => 'event', 'action' => 'view', 'id' => $this->event['id'])); ?>" class="button"><img src="<?php echo $this->imageLink('images/icons/arrow_right.png'); ?>" />Gå til arrangement</a>
    <a href="<?php echo $this->url(array('action' => 'delete', 'id' => $this->shift['id'])); ?>" class="button negative"><img src="<?php echo $this->imageLink('images/icons/delete.png'); ?>" />Slett</a>
</p>

<?php echo $this->flashMessage()->renderMessages(); ?>

<h1>Rediger vakt</h1>

<h2>Tilhørende arrangement</h2>

<?php
    $this->addScriptPath(APPLICATION_PATH . '/modules/core/views/scripts/event');
    echo $this->render('_event.phtml');
?>

<p>&nbsp;</p>

<h2>Detaljer for vakt</h2>
<?php
    $this->form->setAction($this->url());
    echo $this->form;
?>

<p>&nbsp;</p>

<h2>Forespørsler om vaktbytte</h2>

<?php if (sizeof($this->shiftExchanges) > 0): ?>
    <table class="admin_shift_shiftexchanges">
        <thead>
            <tr>
                <th>Rolle</th>
                <th>Fra</th>
                <th>Til</th>
                <th>&nbsp;</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($this->shiftExchanges as $shiftExchange): ?>
                <tr>
                    <td><?php echo $shiftExchange->ShiftRole->Role->name; ?></td>
                    <td><?php echo $shiftExchange->SourceMember->first_name . ' ' . $shiftExchange->SourceMember->last_name; ?></td>
                    <td><?php echo $shiftExchange->TargetMember->first_name . ' ' . $shiftExchange->TargetMember->last_name; ?></td>
                <td><a href="<?php echo $this->url(array('module' => 'admin', 'controller' => 'shift-exchange', 'action' => 'accept', 'id' => $shiftExchange->id)); ?>"><img src="<?php echo $this->imageLink('images/icons/accept.png'); ?>" title="Godkjenn" /></a> <a href="<?php echo $this->url(array('module' => 'admin', 'controller' => 'shift-exchange', 'action' => 'reject', 'id' => $shiftExchange->id)); ?>"><img src="<?php echo $this->imageLink('images/icons/cancel.png'); ?>" title="Avsl&aring;" /></a></td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
<?php else: ?>
    <p>Det har ikke blitt lagt inn noen forespørsler om vaktbytte.</p>
<?php endif; ?>

<p>&nbsp;</p>

<h2>Roller på denne vakten</h2>
<table class="admin_member_roles" id="srtable">
    <thead>
        <tr>
            <th class="shift_role">Rolle</th>
            <th>Medlem</th>
            <th class="shift_leader">Vaktleder</th>
            <th class="control">&nbsp</th>
        </tr>
    </thead>
    <tbody id="srtablebody">
    <?php foreach($this->roles as $role) : ?>
        <tr>
            <td><?php echo $this->escape($role['Role']['name']); ?></td>
            <td id="cell-<?php echo $role['id']; ?>">
            <?php

            if($role['Member'] !== null) :
                echo $role['Member']['last_name'] . ', ' . $role['Member']['first_name'];
            ?>
                <a class="removeMemberLink" href="<?php echo $this->url(array('module' => 'admin', 'controller' => 'shift', 'action' => 'removememberfromrole', 'role' => $role['id']), null, true); ?>"><img src="<?php echo $this->imageLink('images/icons/cross.png'); ?>" alt="Fjern person fra rolle" title="Fjern person fra rolle" /></a>
            <?php endif; ?>
            </td>
            <td class="shift_leader">
                <input class="shiftLeaderCheckBox" type="checkbox" value="<?php echo $role['id']; ?>" id="setLeaderCheckBox-<?php echo $role['id'];?>"<?php echo $role['leader'] == true ? ' checked="true"' : ''; ?>>
            </td>
            <td>
                <a id="member_role_link-<?php echo $role['id']; ?>" class="member_role_link" href="<?php echo $this->url(array('module' => 'admin', 'controller' => 'shift', 'action' => 'memberroletable', 'role' => $role['id']), null, true); ?>"><img src="<?php echo $this->imageLink('images/icons/member_edit.png'); ?>" alt="Endre Person" title="Endre Person" /></a>
                <a class="remove_role_link" href="<?php echo $this->url(array('module' => 'admin', 'controller' => 'shift', 'action' => 'deleteshiftrole', 'role' => $role['id']), null, true); ?>"><img src="<?php echo $this->imageLink('images/icons/cross.png'); ?>" alt="Slett Rolle" title="Slett Rolle" /></a>
            </td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>

<a id="add_shift_role_link" href="#shift_role_form" class="button"><img alt="Legg til rolle" title="Legg til rolle" src="<?php echo $this->imageLink('images/icons/add.png'); ?>">Legg til rolle</a>

<br />
<br />

<div style="display:none">
    <form enctype="application/x-www-form-urlencoded" method="post" accept-charset="UTF-8" action="<?php echo $this->url(array('module' => 'admin', 'controller' => 'shift', 'action' => 'addshiftrole'), null, true); ?>" id="shift_role_form">
        <table class="display" id="shift_role">
            <thead>
                <tr>
                    <th>Rolle</th>
                    <th>Velg</th>
                </tr>
            </thead>
            <tbody>
            <?php foreach($this->allroles as $role) : ?>
                <tr>
                    <td><?php echo $this->escape($role['name']); ?></td>
                    <td><input type="radio" name="role" value="<?php echo $role['id']; ?>"></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        <input type="hidden" name="shift" value="<?php echo $this->shift['id']; ?>">
        <input type="submit" name="submit_add_role_form" id="submit_add_role_form" value="Legg til rolle"/>
    </form>
</div>
